import React, { useState, useEffect } from "react";
//倒计时组件
export default function CountDown(props) {
    const [timer, setTimer] = useState(null);
    const [count, setCount] = useState(30);
    useEffect(() => {
        if (count > 0) {
            let timerID = setTimeout(() => {
                setCount(count - 1);
            }, 1000);
            setTimer(timerID);
        } else {
            setCount(30);
            props.downFinish();
        }
        return () => {
            setTimer(null);
        }
    }, [count])
    return (<div>
        <p>生成区块剩余秒数:{count}</p>
    </div>)
}
